<!-- @module  dicttypeid:businessStatus -->
<!-- @author: YunTao.Li -->
<!-- @description: dict combo  -->
<!-- @since: 2019-11-06 23:46:42 -->
<template>
  <el-select v-model="svalue" placeholder="请选择" :disabled="disabled">
    <el-option
      v-for="item in datas"
      :key="item.value"
      :label="item.label"
      :value="item.value"
    >
      <span style="float: left">{{ item.label }}</span>
    </el-option>
  </el-select>
</template>

<script>

export default {
  props: {
    dicttypeid: {
      type: String,
      default: ''
    },
    value: {
      type: String,
      default: ''
    },
    disabled: {
      type: Boolean,
      default: () => { return false }
    }
  },
  data() {
    return {
      datas: [],
      svalue: ''
    }
  },
  watch: {
    // 判断下拉框的值是否有改变
    svalue(val, oldVal) {
      console.log('new: %s, old: %s', val, oldVal)
      if (val !== oldVal) {
        this.$emit('input', val)
      }
    },
    value(val, oldVal) {
      if (val !== oldVal) {
        this.svalue = this.value.toString()
      }
    }
  },
  mounted() {
    this.svalue = this.value.toString()
    const dictArray = this.getDictArray(this.dicttypeid)
    this.datas = dictArray
  }
}
</script>

<style scoped>
  .el-select{
    width: 100%
  }
</style>
